package sun.superstring.method1reference;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class Test4 {
    public static void main(String[] args) {
        // 目标：理解构造器引用
        // 创建了接口的匿名内部类对象
        /*CarFactory cf = new CarFactory() {
            @Override
            public Car create(String name) {
                return new Car(name);
            }
        };*/

        // 构造器引用
//        CarFactory cf = name -> new Car(name) ;

        // 构造器引用
        CarFactory cf = Car::new; ;


        Car c1 = cf.create("奔驰");
        System.out.println(c1);
    }
}

@FunctionalInterface
interface CarFactory {
    Car create(String name);  // 根据名字name 创建一个Car对象返回
}


@Data
@AllArgsConstructor
@NoArgsConstructor
class Car{
    private String name;
}